package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.utils.Constants;
import com.aaa.utils.RetStatusEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/6/23 9:43
 * @description：所有的controller的父亲
 * @modified By：
 * @version:
 */
@ControllerAdvice
public class BaseController {
    /**
     * @param myReturn
     * @return MyResult
     * @create by: Teacher陈
     * @description: 传入一个原始返回对象，得到一个成功的返回对象
     * @create time: 2020/9/17 9:39
     */
    public  MyReturn getSuccessResult(MyReturn myReturn) {
        if(null==myReturn){
            myReturn= new MyReturn();
        }
        myReturn.setCode(RetStatusEnum.SUCCESS.getCode());
        myReturn.setMsg(RetStatusEnum.SUCCESS.getMessage());
        return myReturn;
    }

    /**
     * @param myReturn
     * @return MyResult
     * @create by: Teacher陈
     * @description: 传入一个原始返回对象，得到一个失败的返回对象
     * @create time: 2020/9/17 9:39
     */
    public  MyReturn getFailResult(MyReturn myReturn) {
        if(null==myReturn){
            myReturn= new MyReturn();
        }
        myReturn.setCode(RetStatusEnum.FAILE.getCode());
        myReturn.setMsg(RetStatusEnum.FAILE.getMessage());
        return myReturn;
    }
    public  MyReturn getLoginFailResult(MyReturn myReturn) {
        if(null==myReturn){
            myReturn= new MyReturn();
        }
        myReturn.setCode(RetStatusEnum.FAILE.getCode());
        myReturn.setMsg(Constants.ERROR_LOGIN);
        return myReturn;
    }

  /*  @ExceptionHandler( Exception.class)
    public ModelAndView toErrorPage(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("500");
        return mv;
    }
    @ExceptionHandler( Exception.class)
    @ResponseBody
    public MyReturn retureErrorInfo(){
        return this.getFailResult(null);
    }*/
}
